import { BaseAPI, route } from "../base";
import type { ActionAmountResult } from "../types/data-contracts";

export interface MigrateThumbnailResult {
  migrated: number;
  skipped: number;
  total: number;
}

export interface CreateThumbnailsForOriginalsResult {
  created: number;
  skipped: number;
  total: number;
}

export class ActionsAPI extends BaseAPI {
  ensureAssetIDs() {
    return this.http.post<void, ActionAmountResult>({
      url: route("/actions/ensure-asset-ids"),
    });
  }

  resetItemDateTimes() {
    return this.http.post<void, ActionAmountResult>({
      url: route("/actions/zero-item-time-fields"),
    });
  }

  ensureImportRefs() {
    return this.http.post<void, ActionAmountResult>({
      url: route("/actions/ensure-import-refs"),
    });
  }

  setPrimaryPhotos() {
    return this.http.post<void, ActionAmountResult>({
      url: route("/actions/set-primary-photos"),
    });
  }

  createMissingThumbnails() {
    return this.http.post<void, ActionAmountResult>({
      url: route("/actions/create-missing-thumbnails"),
    });
  }

  migrateOriginalToThumbnail(dryRun: boolean = false) {
    return this.http.post<void, MigrateThumbnailResult>({
      url: route("/actions/migrate-original-to-thumbnail", { dryRun }),
    });
  }

  createThumbnailsForOriginals(dryRun: boolean = false): Promise<APIResponse<CreateThumbnailsForOriginalsResult>> {
    return this.http.post({
      url: route("/actions/create-thumbnails-for-originals", { dryRun })
    });
  }
}
